```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二叉树深度计算 - 算法可视化</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
        }
        .hero-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #1e293b;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-header {
            background: #0f172a;
            border-top-left-radius: 0.5rem;
            border-top-right-radius: 0.5rem;
            padding: 0.5rem 1rem;
            display: flex;
            align-items: center;
        }
        .code-language {
            color: #f8fafc;
            font-weight: 500;
        }
        .code-body {
            padding: 1rem;
            overflow-x: auto;
        }
        pre {
            margin: 0;
            font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
            color: #f8fafc;
        }
        .method-card {
            transition: all 0.3s ease;
            border-radius: 0.5rem;
            overflow: hidden;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .method-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .complexity-badge {
            display: inline-flex;
            align-items: center;
            padding: 0.25rem 0.5rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 500;
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 1;
            margin-right: 0.5rem;
            margin-top: 0.25rem;
            color: #4f46e5;
            font-weight: 700;
        }
        .mermaid {
            background: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-bg text-white py-20">
        <div class="container mx-auto px-6 lg:px-16 max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">二叉树深度计算</h1>
                    <p class="text-xl md:text-2xl mb-6 opacity-90">探索递归与迭代的算法之美</p>
                    <p class="mb-8 text-lg opacity-85 drop-cap">在计算机科学中，二叉树的深度是一个基础但重要的概念。理解如何计算深度不仅能帮助我们更好地掌握树结构，还能提升我们对递归和迭代算法的认识。</p>
                    <div class="flex space-x-4">
                        <a href="#recursion" class="bg-white text-indigo-700 hover:bg-gray-100 px-6 py-3 rounded-lg font-medium transition duration-300">
                            <i class="fas fa-code-branch mr-2"></i>递归方法
                        </a>
                        <a href="#iteration" class="bg-indigo-700 hover:bg-indigo-800 text-white px-6 py-3 rounded-lg font-medium transition duration-300">
                            <i class="fas fa-project-diagram mr-2"></i>迭代方法
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="mermaid w-full max-w-md">
                        graph TD
                            A[根节点 1] --> B[节点 2]
                            A --> C[节点 3]
                            B --> D[节点 4]
                            B --> E[节点 5]
                            C --> F[null]
                            C --> G[节点 6]
                            E --> H[节点 7]
                            style A fill:#4f46e5,color:white,stroke-width:0
                            style B fill:#7c3aed,color:white,stroke-width:0
                            style C fill:#7c3aed,color:white,stroke-width:0
                            style D fill:#a78bfa,color:white,stroke-width:0
                            style E fill:#a78bfa,color:white,stroke-width:0
                            style G fill:#a78bfa,color:white,stroke-width:0
                            style H fill:#c4b5fd,color:white,stroke-width:0
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Content Section -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6 lg:px-16 max-w-5xl">
            <div class="mb-12">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">二叉树深度概述</h2>
                <p class="text-lg text-gray-700 mb-6">二叉树的<strong>深度</strong>是指从根节点到树中某个节点的最长路径上的节点数。换句话说，树的深度就是树的最长路径所经过的节点数。</p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
                    <div class="bg-indigo-50 p-6 rounded-xl border border-indigo-100">
                        <h3 class="text-xl font-semibold mb-3 text-indigo-800 flex items-center">
                            <i class="fas fa-leaf mr-2"></i>根节点的深度
                        </h3>
                        <p class="text-gray-700">根节点是树的第一个节点，深度为1。作为树的起点，根节点没有父节点。</p>
                    </div>
                    <div class="bg-indigo-50 p-6 rounded-xl border border-indigo-100">
                        <h3 class="text-xl font-semibold mb-3 text-indigo-800 flex items-center">
                            <i class="fas fa-ruler-vertical mr-2"></i>树的深度
                        </h3>
                        <p class="text-gray-700">一棵树的深度是从根节点到其最远叶节点的最长路径上的节点总数。</p>
                    </div>
                </div>
            </div>

            <!-- Recursion Method -->
            <div id="recursion" class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                        <i class="fas fa-code-branch text-indigo-600 text-xl"></i>
                    </div>
                    <h2 class="text-3xl font-bold text-gray-800">递归法 (DFS)</h2>
                </div>
                
                <p class="text-lg text-gray-700 mb-6">递归法是计算二叉树深度的一种常见方法。通过递归遍历树的每一个节点，我们可以计算出左子树和右子树的深度，然后返回这两个深度中的较大者加上1。递归法本质上是一种<strong>深度优先搜索</strong>(DFS)策略。</p>
                
                <div class="method-card bg-white mb-8 border border-gray-200">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">算法思路</h3>
                        <ol class="list-decimal pl-6 space-y-2 text-gray-700">
                            <li>如果树为空(根节点为 <code class="bg-gray-100 px-1 py-0.5 rounded">null</code>)，则深度为0</li>
                            <li>如果树不为空，计算左子树的深度和右子树的深度</li>
                            <li>当前树的深度为左子树和右子树深度的最大值加1(<code class="bg-gray-100 px-1 py-0.5 rounded">1 + max(左子树深度, 右子树深度)</code>)</li>
                        </ol>
                    </div>
                    
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                        </div>
                        <div class="code-body">
                            <pre><code>class TreeNode {
    int val; // 节点值
    TreeNode left; // 左子节点
    TreeNode right; // 右子节点

    TreeNode(int val) {
        this.val = val;
    }
}

public class BinaryTreeDepthDemo {

    // 递归计算二叉树的深度
    public static int maxDepth(TreeNode root) {
        if (root == null) {
            return 0; // 如果节点为空，返回深度0
        }
        int leftDepth = maxDepth(root.left); // 计算左子树的深度
        int rightDepth = maxDepth(root.right); // 计算右子树的深度

        // 当前树的深度为左右子树深度的最大值加1
        return 1 + Math.max(leftDepth, rightDepth);
    }

    public static void main(String[] args) {
        // 构造一个简单的二叉树
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.right = new TreeNode(6);
        root.left.right.left = new TreeNode(7);

        System.out.println("二叉树的深度是: " + maxDepth(root)); // 输出树的深度
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="p-6 bg-gray-50">
                        <div class="flex flex-wrap gap-4 mb-4">
                            <span class="complexity-badge bg-indigo-100 text-indigo-800">
                                <i class="fas fa-clock mr-1"></i>时间复杂度: O(N)
                            </span>
                            <span class="complexity-badge bg-purple-100 text-purple-800">
                                <i class="fas fa-memory mr-1"></i>空间复杂度: O(H)
                            </span>
                        </div>
                        <h4 class="font-medium text-gray-800 mb-2">代码解释</h4>
                        <ul class="list-disc pl-6 text-gray-700 space-y-1">
                            <li><strong>递归基准</strong>：如果当前节点为 <code class="bg-gray-100 px-1 py-0.5 rounded">null</code>，返回深度0。即空树的深度为0</li>
                            <li><strong>递归步骤</strong>：
                                <ul class="list-disc pl-6 mt-1">
                                    <li>计算当前节点的左子树和右子树的深度</li>
                                    <li>使用 <code class="bg-gray-100 px-1 py-0.5 rounded">Math.max</code> 函数获取两个子树深度的较大值</li>
                                    <li>最后返回较大值加1，表示从根节点到最远叶节点的最大距离</li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Iteration Method -->
            <div id="iteration" class="mb-16">
                <div class="flex items-center mb-6">
                    <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                        <i class="fas fa-project-diagram text-indigo-600 text-xl"></i>
                    </div>
                    <h2 class="text-3xl font-bold text-gray-800">迭代法 (BFS)</h2>
                </div>
                
                <p class="text-lg text-gray-700 mb-6">另一种方法是使用<strong>广度优先搜索</strong>(BFS)策略，这种方法通常利用队列来实现。BFS 逐层遍历二叉树，同时记录层数，从而计算树的深度。</p>
                
                <div class="method-card bg-white mb-8 border border-gray-200">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">算法思路</h3>
                        <ol class="list-decimal pl-6 space-y-2 text-gray-700">
                            <li>如果树为空，返回深度0</li>
                            <li>初始化一个队列，将根节点加入队列，初始化深度为0</li>
                            <li>当队列不为空时：
                                <ul class="list-disc pl-6 mt-1">
                                    <li>当前层的节点数量等于队列的长度</li>
                                    <li>对于当前层的每个节点，从队列中移除并将其所有子节点(如果有)加入队列</li>
                                    <li>每遍历完一层，深度加1</li>
                                </ul>
                            </li>
                            <li>最后返回深度</li>
                        </ol>
                    </div>
                    
                    <div class="code-block">
                        <div class="code-header">
                            <span class="code-language">Java</span>
                        </div>
                        <div class="code-body">
                            <pre><code>import java.util.LinkedList;
import java.util.Queue;

public class BinaryTreeDepthDemo {

    // 迭代计算二叉树的深度
    public static int maxDepth(TreeNode root) {
        if (root == null) {
            return 0; // 如果树为空，深度为0
        }

        Queue&lt;TreeNode&gt; queue = new LinkedList&lt;&gt;(); // 队列用于层序遍历
        queue.offer(root); // 将根节点加入队列
        int depth = 0; // 初始化深度

        while (!queue.isEmpty()) {
            int levelSize = queue.size(); // 当前层的节点数
            for (int i = 0; i &lt; levelSize; i++) {
                TreeNode currentNode = queue.poll(); // 取出当前节点
                // 将当前节点的左右子节点加入队列
                if (currentNode.left != null) {
                    queue.offer(currentNode.left);
                }
                if (currentNode.right != null) {
                    queue.offer(currentNode.right);
                }
            }
            depth++; // 每遍历完一层，深度加1
        }

        return depth; // 返回树的深度
    }

    public static void main(String[] args) {
        // 构造一个简单的二叉树
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.right = new TreeNode(6);
        root.left.right.left = new TreeNode(7);

        System.out.println("二叉树的深度是: " + maxDepth(root)); // 输出树的深度
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="p-6 bg-gray-50">
                        <div class="flex flex-wrap gap-4 mb-4">
                            <span class="complexity-badge bg-indigo-100 text-indigo-800">
                                <i class="fas fa-clock mr-1"></i>时间复杂度: O(N)
                            </span>
                            <span class="complexity-badge bg-purple-100 text-purple-800">
                                <i class="fas fa-memory mr-1"></i>空间复杂度: O(W)
                            </span>
                        </div>
                        <h4 class="font-medium text-gray-800 mb-2">代码解释</h4>
                        <ul class="list-disc pl-6 text-gray-700 space-y-1">
                            <li><strong>队列初始化</strong>：将根节点加入队列</li>
                            <li><strong>层序遍历</strong>：
                                <ul class="list-disc pl-6 mt-1">
                                    <li>遍历队列中所有节点，计算每一层的节点数</li>
                                    <li>将所有子节点加入队列，完成当前层次的遍历后，深度加1</li>
                                </ul>
                            </li>
                            <li><strong>循环终止</strong>：队列为空时，表示所有节点都已遍历，返回深度</li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Comparison Section -->
            <div class="bg-indigo-50 rounded-xl p-8 mb-12">
                <h2 class="text-2xl font-bold mb-6 text-indigo-800">方法对比</h2>
                <div class="overflow-x-auto">
                    <table class="min-w-full bg-white rounded-lg overflow-hidden">
                        <thead>
                            <tr class="bg-indigo-100 text-indigo-800">
                                <th class="py-3 px-4 text-left font-semibold">对比维度</th>
                                <th class="py-3 px-4 text-left font-semibold">递归法 (DFS)</th>
                                <th class="py-3 px-4 text-left font-semibold">迭代法 (BFS)</th>
                            </tr>
                        </thead>
                        <tbody class="divide-y divide-gray-200">
                            <tr>
                                <td class="py-3 px-4 font-medium">实现复杂度</td>
                                <td class="py-3 px-4">简单直接，代码更简洁</td>
                                <td class="py-3 px-4">需要维护队列，代码稍复杂</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4 font-medium">适用场景</td>
                                <td class="py-3 px-4">适用于深度优先遍历场景</td>
                                <td class="py-3 px-4">适用于广度优先遍历或需要层序遍历的场景</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4 font-medium">空间效率</td>
                                <td class="py-3 px-4">最坏情况(树退化为链表)下空间复杂度为O(N)</td>
                                <td class="py-3 px-4">空间消耗取决于树的最大宽度</td>
                            </tr>
                            <tr>
                                <td class="py-3 px-4 font-medium">可读性</td>
                                <td class="py-3 px-4">对于熟悉递归的开发者更易理解</td>
                                <td class="py-3 px-4">对于初学者可能更直观，因为避免了递归</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-6 lg:px-16 max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索算法之美，分享技术之道</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300 flex items-center">
                        <i class="fas fa-link mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```